package com.example.OnlineStorage.pojo.entity;


import com.google.gson.*;

import java.lang.reflect.Type;

public class NodeDeserializer implements JsonDeserializer<Node> {
    public Node deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
            throws JsonParseException {
        JsonObject jsonObject = json.getAsJsonObject();
        String typeName = jsonObject.get("type").getAsJsonPrimitive().getAsString();

        if ("Directory".equals(typeName)) {
            return context.deserialize(jsonObject, Directory.class);
        } else{
            return context.deserialize(jsonObject, File.class);
        }
    }
}